--- title: "最小的和" created: 2025-11-28 tags: - 算法 --- # 最小的和 ## 题目 [最小的和](https://www.acwing.com/problem/content/3998/) ![[image-91f419af.png]] ## 思路分析 ![[image-0174a044.png]] 我的这种分析貌似没用到多路归并 贪心加大根堆解决了 ## 代码实现 ```cpp #include using namespace std; typedef long long LL; const int N=1e3+10; int a[N],b[N]; priority_queue heap; int n,k1,k2; int main() { cin>>n>>k1>>k2; for(int i=1;i<=n;i++) cin>>a[i]; for(int i=1;i<=n;i++){ cin>>b[i]; heap.push(abs(a[i]-b[i])); } for(int i=1;i<=k1+k2;i++){ auto temp=heap.top(); heap.pop(); heap.push(abs(temp-1)); } LL res=0; while(!heap.empty()){ auto temp=heap.top(); heap.pop(); res+=temp*temp; } cout<